const db = require('../DBcofig/DBConnection')
module.exports = {
    getCostmange(req, res) {
        let { value } = req.query
        // console.log(value);
        let pagesMax = 5
        let qishi = (value - 1) * pagesMax
        let sql = 'select * from consume limit ?,?'
        let arr = [qishi, pagesMax]
        db.dbconfig(res, sql, arr, function (data) {
            // console.log(data);
            let shuju = data
            let sql = "select count(*) AS 'count' from consume"
            let arr = []
            db.dbconfig(res, sql, arr, function (data) {
                if (data !== null) {
                    res.send({
                        code: 200,
                        msg: '查询成功',
                        data: shuju,
                        count: data
                    })
                }
            })

        })
    },
    selectCostMsg(req, res) {
        let { values, pages, times } = req.query
        console.log(values, pages, times);
        let pagesMax = 5
        let qishi = (pages - 1) * pagesMax
        let arr = []
        let sql1 = "select count(*) AS 'count' from consume where 1=1"
        let sql = "select * from consume where 1=1"
        if (values !== undefined && values !== '') {
            sql1 += " and consume_zynum like ?"
            sql += " and consume_zynum like ?"
            arr.push(values + "%")
        }
        if (times !== undefined && times !== '') {
            console.log(times, 123);
            sql1 += ' and consume_time = ?'
            sql += ' and consume_time = ?'
            arr.push(times)
            console.log(sql, 123);
        }
        db.dbconfig(res, sql1, arr, function (data) {
            let shuju1 = data
            sql += " limit ?,?"
            arr.push(qishi, pagesMax)
            console.log(sql, arr);
            db.dbconfig(res, sql, arr, function (data) {
                let shuju = data
                res.send({
                    code: 200,
                    msg: "查询成功123",
                    data: shuju,
                    count: shuju1
                })
            })

        })
    },
    getAllmsg(req, res) {
        let sql = "select * from all_msg"
        let arr = []
        db.dbconfig(res, sql, arr, function (data) {
            // console.log(data);
            res.send({
                code: 200,
                msg: "查询成功",
                data: data
            })
        })
    }
}